import { defineStore } from 'pinia'
import { getCategory1, getCategory2, getCategory3 } from '@/api/product/attr'
import type { Get_C1_Data } from '@/api/product/attr/type'
import type { Category } from './type'
const categoryStore = defineStore('categoryStore', {
    state: (): Category => ({
        C1Id: '',
        C1Arr: [],
        C2Id: '',
        C2Arr: [],
        C3Id: '',
        C3Arr: [],
    }),
    actions: {
        async getC1gData() {
            const data: Get_C1_Data = await getCategory1()
            if (data.code === 200) {
                this.C1Arr = data.data
            }
        },
        async getC2gData() {
            const data: Get_C1_Data = await getCategory2(this.C1Id)
            if (data.code === 200) {
                this.C2Arr = data.data
            }
        },
        async getC3gData() {
            const data: Get_C1_Data = await getCategory3(this.C2Id)
            if (data.code === 200) {
                this.C3Arr = data.data
            }
        },
    },
    getters: {},
})

export default categoryStore
